<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>Docker基础学习文档(包括安装教程) | 飞の博客</title><meta name="author" content="Fei"><meta name="copyright" content="Fei"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="ffffff"><meta name="description" content="Docker基础学习文档(包括安装教程)">
<meta property="og:type" content="article">
<meta property="og:title" content="Docker基础学习文档(包括安装教程)">
<meta property="og:url" content="https://tengfei2233.gitee.io/2023/8/27/Docker%E5%9F%BA%E7%A1%80%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3-%E5%8C%85%E6%8B%AC%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/index.html">
<meta property="og:site_name" content="飞の博客">
<meta property="og:description" content="Docker基础学习文档(包括安装教程)">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg">
<meta property="article:published_time" content="2023-08-27T15:29:15.000Z">
<meta property="article:modified_time" content="2023-08-27T15:29:15.000Z">
<meta property="article:author" content="Fei">
<meta property="article:tag" content="Docker">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg"><link rel="shortcut icon" href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/icon.png"><link rel="canonical" href="https://tengfei2233.gitee.io/2023/8/27/Docker%E5%9F%BA%E7%A1%80%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3-%E5%8C%85%E6%8B%AC%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="msvalidate.01" content="2ADFA30867CBC6E090E3C5B244DC311D"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.3.0/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?07a1f58fb95d3d4a97c2ae0a181c9964";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":200},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.staticfile.org/flickr-justified-gallery/2.1.2/fjGallery.min.js',
      css: 'https://cdn.staticfile.org/flickr-justified-gallery/2.1.2/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Docker基础学习文档(包括安装教程)',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-08-27 23:29:15'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', 'ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (false) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/fei.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">24</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg')"><nav id="nav"><span id="blog-info"><a href="/" title="飞の博客"><span class="site-name">飞の博客</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友情链接</span></a></div><div class="menus_item"><a class="site-page" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Docker基础学习文档(包括安装教程)</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-08-27T15:29:15.000Z" title="发表于 2023-08-27 23:29:15">2023-08-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-08-27T15:29:15.000Z" title="更新于 2023-08-27 23:29:15">2023-08-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Docker/">Docker</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">3.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>11分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Docker基础学习文档(包括安装教程)"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="Docker基础学习文档"><a href="#Docker基础学习文档" class="headerlink" title="Docker基础学习文档"></a>Docker基础学习文档</h2><h5 id="下一篇Docker文章：Dockerfile学习"><a href="#下一篇Docker文章：Dockerfile学习" class="headerlink" title="下一篇Docker文章：Dockerfile学习"></a>下一篇Docker文章：<a target="_blank" rel="noopener" href="https://blog.tengfei.tech/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/"><font color="red">Dockerfile学习</font></a></h5><h3 id="Docker介绍"><a href="#Docker介绍" class="headerlink" title="Docker介绍"></a>Docker介绍</h3><h4 id="什么是Docker"><a href="#什么是Docker" class="headerlink" title="什么是Docker"></a>什么是Docker</h4><blockquote>
<p><strong>引用<a target="_blank" rel="noopener" href="https://docs.docker.com/get-started/overview/">Docker官网的介绍</a></strong></p>
<p>Docker是一个用于开发、发布和运行应用程序的开放平台。Docker使您能够将应用程序从基础设施中分离出来，以便快速交付软件。使用Docker，您可以像管理应用程序一样管理基础架构。通过利用Docker的方法来交付、测试和部署代码，您可以显著减少编写代码和在生产环境中运行代码之间的延迟。</p>
<p><strong>而以我个人通俗的理解呢</strong></p>
<p>Docker是一个安装在操作系统上的虚拟机，是一个特别的虚拟机，这个虚拟机只能运行容器；一个容器就像一个环境集合。</p>
<p>就像MySQL容器，里面包含了MySQL运行所需要的所有环境，对这个环境进行打包，就是一个镜像；将这个镜像在Docker上运行，就生成了一个MySQL服务，这个服务就是容器。</p>
</blockquote>
<h4 id="什么是镜像"><a href="#什么是镜像" class="headerlink" title="什么是镜像"></a>什么是镜像</h4><blockquote>
<p>什么是镜像呢？就像有一天你在路上看到一片很好看的晚霞，你把这片晚霞用相机保存下来，生成了一张照片；照片保存了这一时刻的晚霞，他不随着时间流逝，你可以将这张照片分享给任何人。</p>
<p>回过头来看，我把MySQL运行所需要的环境保存下来，进行打包，而打成的包就成了一个镜像，你可以将镜像给任何人，他就能在Docker上运行这个镜像；因此你可以把镜像看成是一个安装包。</p>
</blockquote>
<h4 id="什么是容器"><a href="#什么是容器" class="headerlink" title="什么是容器"></a>什么是容器</h4><blockquote>
<p>接着上面：我们把安装包分享给了别人，别人得安装吧，要不然怎么使用这个软件，而使用安装包被安装后就成为了我们手机&#x2F;电脑上的软件。</p>
<p>那么显而易见，镜像就相当于安装包，容器就是安装后的软件，只不过这个安装包有点特殊，只能安装在Docker上。我们将这个镜像分享给别人，别人使用这个镜像就能安装生成容器了。</p>
</blockquote>
<h4 id="什么是镜像仓库呢"><a href="#什么是镜像仓库呢" class="headerlink" title="什么是镜像仓库呢"></a>什么是镜像仓库呢</h4><blockquote>
<p>还是我们的安装包为例子：有一天你想要一个有趣的软件的安装包，可是你没有，但是小明有，你去找小明要，小明就将它发给你，但是后来，越来越多的人发现，你用着有趣的安装包，他们也想要，于是他们就都去找小明，显然小明是忙不过来的，于是他就将这个安装包上传到了应用商店，人人都可以去上面下载了。</p>
<p>而镜像仓库就像这个软件商店类似，人们在上面上传一些镜像，供所有人下载；可是镜像仓库又分为公共仓库和私有仓库：</p>
<p><strong>公共仓库：</strong></p>
<p>就是任何人都能在上面下载镜像，一般常用服务的官方镜像也在这个上面，比如：<a target="_blank" rel="noopener" href="https://hub.docker.com/">Docker的官方镜像仓库</a>。</p>
<p><strong>私有仓库：</strong></p>
<p>一般由个人或则公司搭建的私有仓库，自能供有权限的人下载。</p>
</blockquote>
<h4 id="为什么要使用Docker呢"><a href="#为什么要使用Docker呢" class="headerlink" title="为什么要使用Docker呢"></a>为什么要使用Docker呢</h4><blockquote>
<p>**为什么要使用Docker呢：**有这样一个场景，你们团队准备开发一款App，那么便涉及到了多个外部服务，像数据库，缓存，消息队列，不同编程语言环境等，这样的话在开发过程中你们开发，运维，测试都需要安装这样一套环境，可能第一次还好，如果哪天环境中软件的版本需要变动，可能需要重新安装一遍；安装过这种服务的同学都知道，那是相当刺激的，因此对谁来说都不乐意了。</p>
<p>可能有同学会说，我们可以使用虚拟机啊，一个虚拟机克隆几份；是的，是可以用虚拟机，Docker的本质也是虚拟机；但是传统的虚拟机太笨重了，每次启动都要好久，且占用系统资源过高，可能我运行一个虚拟机占用的内存比我一整套服务占用的内存都高，这是得不偿失的。</p>
<p>Docker的话相对于传统虚拟机，更加轻量化，占用内存少，启动迅速，镜像共享性高，这便是最大的有点；相对来说Docker也是有缺点的，那就是相对于传统虚拟机，虚拟化程度不高，不能做到与操作系统环境完全隔离，毕竟很多api要依赖于操作系统，但是对于我们这种对虚拟化要求不高的项目来说，用Docker是非常优的选择。</p>
</blockquote>
<h4 id="Docker的基本架构"><a href="#Docker的基本架构" class="headerlink" title="Docker的基本架构"></a>Docker的基本架构</h4><blockquote>
<p>Docker使用经典的C&#x2F;S架构，分为Docker Client与Docker Server；Docker Client用于接受用户输入的指令，展示Docker运行信息等；Docker Server处理Docker Client接受的指令，运行容器，构建容器等。</p>
<p>一般我们都是将Docker Client与Docker Server安装在同一个操作系统上，所有感知不强；对于一些企业，Docker Client与Docker Server都安装在不同的系统上。</p>
</blockquote>
<h3 id="安装Docker"><a href="#安装Docker" class="headerlink" title="安装Docker"></a>安装Docker</h3><blockquote>
<p>Docker是由Go语言开发的一款软件，由于Go并非是跨操作系统的语言，且官方只对Linux&#x2F;Unix系统做了适配，所以Docker只能安装在这些系统上。</p>
<p>至于想将Docker安装在Windows上，可以看看使用<a target="_blank" rel="noopener" href="https://learn.microsoft.com/zh-cn/windows/wsl/">适用于 Linux 的 Windows 子系统文档 | Microsoft Learn</a>的实现方式，不过本质上还是安装在Linux上。</p>
<p>以下我讲讲如何分别在Centos7和Ubuntu20上安装Docker</p>
</blockquote>
<h4 id="在Centos7上安装Docker"><a href="#在Centos7上安装Docker" class="headerlink" title="在Centos7上安装Docker"></a>在Centos7上安装Docker</h4><ul>
<li>卸载原系统存在的Docker</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">yum remove docker \</span><br><span class="line">                  docker-client \</span><br><span class="line">                  docker-client-latest \</span><br><span class="line">                  docker-common \</span><br><span class="line">                  docker-latest \</span><br><span class="line">                  docker-latest-logrotate \</span><br><span class="line">                  docker-logrotate \</span><br><span class="line">                  docker-engine</span><br></pre></td></tr></table></figure>

<ul>
<li>下载Docker的yum repo</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">推荐使用国内的（此处以阿里云的为例）</span></span><br><span class="line">yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo</span><br></pre></td></tr></table></figure>

<ul>
<li>更新yum并下载docker</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更新yum</span></span><br><span class="line">yum -y update</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">下载运行依赖的工具</span></span><br><span class="line">yum install -y yum-utils device-mapper-persistent-data lvm2</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装Docker CE（ce指Community Edition，社区版，企业版需要money的）</span></span><br><span class="line">yum install -y docker-ce</span><br></pre></td></tr></table></figure>

<ul>
<li>启动docker</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动docker</span></span><br><span class="line">systemctl start docker </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将docker加入开机自启</span></span><br><span class="line">systemctl enable docker</span><br></pre></td></tr></table></figure>

<h4 id="在Ununtu20上安装Docker（如果非管理员记得所以命令前加sudo）"><a href="#在Ununtu20上安装Docker（如果非管理员记得所以命令前加sudo）" class="headerlink" title="在Ununtu20上安装Docker（如果非管理员记得所以命令前加sudo）"></a>在Ununtu20上安装Docker（如果非管理员记得所以命令前加sudo）</h4><ul>
<li>卸载原系统上存在的Docker</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">sudo apt-get remove docker docker.io docker-doc docker-compose podman-docker containerd runc</span><br></pre></td></tr></table></figure>

<ul>
<li>更新apt，下载运行依赖工具包</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更新apt</span></span><br><span class="line">sudo apt-get update</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">下载依赖工具包</span></span><br><span class="line">sudo apt-get install ca-certificates curl gnupg</span><br></pre></td></tr></table></figure>

<ul>
<li>设置官方GPG key</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">依次执行以下命令</span></span><br><span class="line">sudo install -m 0755 -d /etc/apt/keyrings</span><br><span class="line"></span><br><span class="line">curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg</span><br><span class="line"></span><br><span class="line">sudo chmod a+r /etc/apt/keyrings/docker.gpg</span><br></pre></td></tr></table></figure>

<ul>
<li>设置存储库</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line">echo \</span><br><span class="line">  &quot;deb [arch=&quot;$(dpkg --print-architecture)&quot; signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu \</span><br><span class="line">  &quot;$(. /etc/os-release &amp;&amp; echo &quot;$VERSION_CODENAME&quot;)&quot; stable&quot; | \</span><br><span class="line">  sudo tee /etc/apt/sources.list.d/docker.list &gt; /dev/null</span><br></pre></td></tr></table></figure>

<ul>
<li>安装Docker</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">再次更新apt</span></span><br><span class="line">sudo apt-get update  </span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">安装docker</span></span><br><span class="line">sudo apt-get install docker-ce</span><br></pre></td></tr></table></figure>

<ul>
<li>启动Docker</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动docker</span></span><br><span class="line">sudo systemctl start docker </span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将docker加入开机自启</span></span><br><span class="line">sudo systemctl enable docker</span><br></pre></td></tr></table></figure>

<h4 id="配置Docker仓库镜像源"><a href="#配置Docker仓库镜像源" class="headerlink" title="配置Docker仓库镜像源"></a>配置Docker仓库镜像源</h4><ul>
<li>在&#x2F;etc&#x2F;docker目录下新建一个daemon.json文件（有就直接编辑）,添加以下内容</li>
</ul>
<figure class="highlight json"><table><tr><td class="code"><pre><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">  <span class="attr">&quot;registry-mirrors&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span></span><br><span class="line">     <span class="string">&quot;https://mirror.ccs.tencentyun.com&quot;</span><span class="punctuation">,</span></span><br><span class="line">     <span class="string">&quot;https://xxxx.mirror.aliyuncs.com&quot;</span><span class="punctuation">,</span></span><br><span class="line">     <span class="string">&quot;https://hub-mirror.c.163.com&quot;</span></span><br><span class="line">    <span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line"></span><br><span class="line"><span class="attr">&quot;log-driver&quot;</span><span class="punctuation">:</span><span class="string">&quot;json-file&quot;</span><span class="punctuation">,</span></span><br><span class="line">    <span class="attr">&quot;log-opts&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">        <span class="attr">&quot;max-size&quot;</span> <span class="punctuation">:</span><span class="string">&quot;50m&quot;</span><span class="punctuation">,</span><span class="attr">&quot;max-file&quot;</span><span class="punctuation">:</span><span class="string">&quot;3&quot;</span></span><br><span class="line">    <span class="punctuation">&#125;</span></span><br><span class="line"></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<ul>
<li>这个三个镜像源分别是腾讯云，阿里云，网易的，其中阿里云的需要你们登录账号自己去获取，替换xxx的部分即可</li>
<li>这个log-driver指的是设置每个容器的日志文件大小，总大小50M，最多分三个文件</li>
</ul>
<h3 id="Docker命令介绍"><a href="#Docker命令介绍" class="headerlink" title="Docker命令介绍"></a>Docker命令介绍</h3><h4 id="镜像管理类命令"><a href="#镜像管理类命令" class="headerlink" title="镜像管理类命令"></a>镜像管理类命令</h4><ul>
<li>docker images</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">列出当前Docker下的所有镜像</span> </span><br><span class="line">docker images</span><br></pre></td></tr></table></figure>

<ul>
<li>docker pull</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将仓库镜像从中央仓库下载到本地，比如下载Redis</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">不带版本下载最新的</span></span><br><span class="line">docker pull redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">带版本</span></span><br><span class="line">docker pull redis:6.0.2</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">指定远程仓库</span></span><br><span class="line">docker pull xxx.xxx/redis:6.0.2</span><br></pre></td></tr></table></figure>

<ul>
<li>docker push</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将镜像推送到远程仓库</span></span><br><span class="line">docker push my-redis:v1.0</span><br></pre></td></tr></table></figure>

<ul>
<li>docker rmi</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除本地仓库指定镜像</span></span><br><span class="line">docker rmi redis:6.0.2</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按<span class="built_in">id</span>删除</span></span><br><span class="line">docker rmi 镜像id</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除多个</span></span><br><span class="line">docker rmi image1 image2</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除未使用的镜像</span></span><br><span class="line">docker rmi prune</span><br></pre></td></tr></table></figure>

<h4 id="容器管理类命令"><a href="#容器管理类命令" class="headerlink" title="容器管理类命令"></a>容器管理类命令</h4><ul>
<li>docker run</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">运行一个镜像（镜像不存在的话就会去下载）</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">直接运行，容器名称就是镜像名称（加上-d便是后台模式）</span></span><br><span class="line">docker run redis</span><br><span class="line">docker run -d redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">指定镜像名称与暴露端口</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">指定名称好管理，暴露端口是便于访问，一般都暴露端口，本机端口:容器端口，将本机端口映射到容器端口</span></span><br><span class="line">docker --name redis1 \</span><br><span class="line">-p 6379:6379 \</span><br><span class="line">-d redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">映射文件目录</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将容器目录与本机目录进行映射 本机目录:容器目录</span></span><br><span class="line">docker --name redis1 \</span><br><span class="line">-p 6379:6379 \</span><br><span class="line">-v /usr/local/redis:/usr/local/redis \</span><br><span class="line">-d redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">设置环境变量</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">设置容器内环境变量name=xiaoming，容器服务可以使用这个环境变量</span></span><br><span class="line">docker --name redis1 \</span><br><span class="line">-p 6379:6379 \</span><br><span class="line">-v /usr/local/redis:/usr/local/redis \</span><br><span class="line">-e name=xiaoming \</span><br><span class="line">-d redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">设置启动策略</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">这里设置docker启动，容器自启</span></span><br><span class="line">docker --name redis1 \</span><br><span class="line">-p 6379:6379 \</span><br><span class="line">-v /usr/local/redis:/usr/local/redis \</span><br><span class="line">--restart=always \</span><br><span class="line">-e name=xiaoming \</span><br><span class="line">-d redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">链接到另一个容器</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">一般这种情况是我需要访问到其它容器--<span class="built_in">link</span> &lt;container_name&gt;:&lt;<span class="built_in">alias</span>&gt;</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">不过这个参数目前弃用了，官方更建议使用自定义网络的方式--network=&lt;network_name&gt;</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">创建mynetwork网络</span></span><br><span class="line">docker network create mynetwork</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">使用该网络</span></span><br><span class="line">docker --name redis1 \</span><br><span class="line">-p 6379:6379 \</span><br><span class="line">-v /usr/local/redis:/usr/local/redis \</span><br><span class="line">--restart=always \</span><br><span class="line">--network=mynetwork \</span><br><span class="line">-e name=xiaoming \</span><br><span class="line">-d redis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">关于docker网络的布局，可以参考https://www.bilibili.com/video/BV1Aj411r71b/</span></span><br></pre></td></tr></table></figure>

<p><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-8-23/docker-network.png"></p>
<ul>
<li>docker start</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器名称启动容器</span></span><br><span class="line">docker start myredis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器<span class="built_in">id</span>启动容器</span></span><br><span class="line">docker start xxxx</span><br></pre></td></tr></table></figure>

<ul>
<li>docker stop</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器名称停止容器</span></span><br><span class="line">docker stop myredis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器<span class="built_in">id</span>停止容器</span></span><br><span class="line">docker stop xxxx</span><br></pre></td></tr></table></figure>

<ul>
<li>docker restart</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器名称重启容器</span></span><br><span class="line">docker restart myredis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器<span class="built_in">id</span>重启容器</span></span><br><span class="line">docker restart xxxx</span><br></pre></td></tr></table></figure>

<ul>
<li>docker rm</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">前提是容器已经停止了</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器名称删除容器</span></span><br><span class="line">docker rm myredis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器<span class="built_in">id</span>删除容器</span></span><br><span class="line">docker rm xxxx</span><br></pre></td></tr></table></figure>

<ul>
<li>docker ps</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">列出正在运行的容器</span></span><br></pre></td></tr></table></figure>

<ul>
<li>docker ps -a</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">列出所有的容器，包括已停止的容器。</span></span><br></pre></td></tr></table></figure>

<ul>
<li>docker cp</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将docker容器中文件拷贝到宿主机</span></span><br><span class="line">docker cp 容器id:文件/文件夹 主机路径</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">将主机文件拷贝到docker容器</span></span><br><span class="line">docker cp 宿主机文件/文件夹 容器id:容器内路径</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">除了使用文件拷贝外，容器与宿主机之间还可以通过-v绑定volume</span></span><br></pre></td></tr></table></figure>

<h4 id="容器日志和执行类命令"><a href="#容器日志和执行类命令" class="headerlink" title="容器日志和执行类命令"></a>容器日志和执行类命令</h4><ul>
<li>docker logs</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器名称查看容器日志</span></span><br><span class="line">docker logs myredis</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">按容器<span class="built_in">id</span>查看容器日志</span></span><br><span class="line">docker logs xxxx</span><br></pre></td></tr></table></figure>

<ul>
<li>docker exec -it</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入容器内部使用bash解释器</span></span><br><span class="line">docker exec -it 容器名称|容器id bash</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">进入容器内部使用sh解释器</span></span><br><span class="line">docker exec -it 容器名称|容器id sh</span><br></pre></td></tr></table></figure>

<h4 id="镜像构建和管理类命令"><a href="#镜像构建和管理类命令" class="headerlink" title="镜像构建和管理类命令"></a>镜像构建和管理类命令</h4><ul>
<li>docker build -t</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">根据当前路径下Dockerfile文件构建一个名为myredis的镜像（注意末尾的一个点代表当前路径，不能省略）</span></span><br><span class="line">docker build -t myredis .</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">根据/usr/local路径下Dockerfile文件构建一个名为myredis的镜像</span></span><br><span class="line">docker build -t myredis -f /usr/local/Dockerfile .</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">根据url下的Dockerfile构建镜像</span></span><br><span class="line">docker build -t myredis http://xx.xx</span><br></pre></td></tr></table></figure>

<ul>
<li>docker tag</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">更换标签便于容器的管理</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">根据容器名称，给名为myredis:v1.0的容器创建一个名为myredis:latest标签的副本</span></span><br><span class="line">docker tag myredis:v1.0 myredis:latest</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash"><span class="comment"># 根据容器名称，给id为a1b2c334的容器创建一个名为myredis:latest标签的副本</span></span></span><br><span class="line">docker tag a1b2c334 myredis:latest</span><br></pre></td></tr></table></figure>

<ul>
<li>docker commit</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">根据当前容器的状态创建一个新的容器</span></span><br><span class="line">docker commit 容器名|容器id 新容器名称</span><br></pre></td></tr></table></figure>

<h4 id="网络和存储管理类命令"><a href="#网络和存储管理类命令" class="headerlink" title="网络和存储管理类命令"></a>网络和存储管理类命令</h4><ul>
<li>docker network ls</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">列出当前Docker网络</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">以下为各网络的特点</span></span><br></pre></td></tr></table></figure>

<p><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-8-23/docker-network.png"></p>
<ul>
<li>docker network create</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">创建一个名为mynet的自定义网络，也叫自定义Bridge，其实docker网络就是一个虚拟网桥</span></span><br><span class="line">docker network create mynet</span><br></pre></td></tr></table></figure>

<ul>
<li>docker volume ls</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">列出当前的volume卷</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">卷就是容器与宿主机间共享的数据，容器损坏后，防止数据丢失</span></span><br></pre></td></tr></table></figure>

<ul>
<li>docker volume create</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">创建一个名为myvolume的卷</span></span><br><span class="line">docker volume myvolume</span><br></pre></td></tr></table></figure>

<h4 id="Docker-Compose-相关命令"><a href="#Docker-Compose-相关命令" class="headerlink" title="Docker Compose 相关命令"></a>Docker Compose 相关命令</h4><ul>
<li>docker-compose up</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">启动docker-compose.yml中定义的一系列服务（docker-compose.yml在当前目录下）</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">-d是指以守护进程模式运行，就是在后台运行</span></span><br><span class="line">docker-compose up -d</span><br></pre></td></tr></table></figure>

<ul>
<li>docker-compose stop</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">停止docker-compose.yml中定义的一系列服务（docker-compose.yml在当前目录下）</span></span><br><span class="line">docker-compose stop</span><br></pre></td></tr></table></figure>

<ul>
<li>docker-compose down</li>
</ul>
<figure class="highlight shell"><table><tr><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">删除docker-compose.yml中定义的一系列服务，包括其中的容器，自定义网络，自定义卷等</span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">docker-compose.yml在当前目录下</span></span><br><span class="line">docker-compose down</span><br></pre></td></tr></table></figure>

<h4 id="关于Docker的其它命令，以后用到了再做补充……"><a href="#关于Docker的其它命令，以后用到了再做补充……" class="headerlink" title="关于Docker的其它命令，以后用到了再做补充……"></a>关于Docker的其它命令，以后用到了再做补充……</h4></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://tengfei2233.gitee.io">Fei</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://tengfei2233.gitee.io/2023/8/27/Docker%E5%9F%BA%E7%A1%80%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3-%E5%8C%85%E6%8B%AC%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/">https://tengfei2233.gitee.io/2023/8/27/Docker%E5%9F%BA%E7%A1%80%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3-%E5%8C%85%E6%8B%AC%E5%AE%89%E8%A3%85%E6%95%99%E7%A8%8B/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://tengfei2233.gitee.io" target="_blank">飞の博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Docker/">Docker</a></div><div class="post_share"><div class="social-share" data-image="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/wechat.png" target="_blank"><img class="post-qr-code-img" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/wechat.png" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/alipay.png" target="_blank"><img class="post-qr-code-img" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/alipay.png" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/6/26/Docker%E5%AE%89%E8%A3%85%E4%B8%80%E4%BA%9B%E5%B8%B8%E7%94%A8%E8%BD%AF%E4%BB%B6%EF%BC%88%E6%9B%B4%E6%96%B0%E4%B8%AD-%EF%BC%89/" title="Docker安装一些常用软件（更新中！）"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Docker安装一些常用软件（更新中！）</div></div></a></div><div class="next-post pull-right"><a href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Dockerfile学习</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2023/6/26/Docker%E5%AE%89%E8%A3%85%E4%B8%80%E4%BA%9B%E5%B8%B8%E7%94%A8%E8%BD%AF%E4%BB%B6%EF%BC%88%E6%9B%B4%E6%96%B0%E4%B8%AD-%EF%BC%89/" title="Docker安装一些常用软件（更新中！）"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-07-31</div><div class="title">Docker安装一些常用软件（更新中！）</div></div></a></div><div><a href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-08-27</div><div class="title">Docker Compose学习</div></div></a></div><div><a href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img class="cover" src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="fas fa-history fa-fw"></i> 2023-08-27</div><div class="title">Dockerfile学习</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/common/fei.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Fei</div><div class="author-info__description">当你想起来了，那就记录一点吧</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">24</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">28</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">16</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/tengfei2233"><i class="fab fa-github"></i><span>关注我</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/tengfei2233" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://gitee.com/tengfei2233" target="_blank" title="Gitee"><i class="fab fa-git"></i></a><a class="social-icon" href="/youfeige@outlook.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">当你迷茫的时候，那就静下心想想吧！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Docker%E5%9F%BA%E7%A1%80%E5%AD%A6%E4%B9%A0%E6%96%87%E6%A1%A3"><span class="toc-number">1.</span> <span class="toc-text">Docker基础学习文档</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%8B%E4%B8%80%E7%AF%87Docker%E6%96%87%E7%AB%A0%EF%BC%9ADockerfile%E5%AD%A6%E4%B9%A0"><span class="toc-number">1.0.0.1.</span> <span class="toc-text">下一篇Docker文章：Dockerfile学习</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.1.</span> <span class="toc-text">Docker介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFDocker"><span class="toc-number">1.1.1.</span> <span class="toc-text">什么是Docker</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E9%95%9C%E5%83%8F"><span class="toc-number">1.1.2.</span> <span class="toc-text">什么是镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E5%AE%B9%E5%99%A8"><span class="toc-number">1.1.3.</span> <span class="toc-text">什么是容器</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93%E5%91%A2"><span class="toc-number">1.1.4.</span> <span class="toc-text">什么是镜像仓库呢</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%BA%E4%BB%80%E4%B9%88%E8%A6%81%E4%BD%BF%E7%94%A8Docker%E5%91%A2"><span class="toc-number">1.1.5.</span> <span class="toc-text">为什么要使用Docker呢</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Docker%E7%9A%84%E5%9F%BA%E6%9C%AC%E6%9E%B6%E6%9E%84"><span class="toc-number">1.1.6.</span> <span class="toc-text">Docker的基本架构</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%89%E8%A3%85Docker"><span class="toc-number">1.2.</span> <span class="toc-text">安装Docker</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9C%A8Centos7%E4%B8%8A%E5%AE%89%E8%A3%85Docker"><span class="toc-number">1.2.1.</span> <span class="toc-text">在Centos7上安装Docker</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9C%A8Ununtu20%E4%B8%8A%E5%AE%89%E8%A3%85Docker%EF%BC%88%E5%A6%82%E6%9E%9C%E9%9D%9E%E7%AE%A1%E7%90%86%E5%91%98%E8%AE%B0%E5%BE%97%E6%89%80%E4%BB%A5%E5%91%BD%E4%BB%A4%E5%89%8D%E5%8A%A0sudo%EF%BC%89"><span class="toc-number">1.2.2.</span> <span class="toc-text">在Ununtu20上安装Docker（如果非管理员记得所以命令前加sudo）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%85%8D%E7%BD%AEDocker%E4%BB%93%E5%BA%93%E9%95%9C%E5%83%8F%E6%BA%90"><span class="toc-number">1.2.3.</span> <span class="toc-text">配置Docker仓库镜像源</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker%E5%91%BD%E4%BB%A4%E4%BB%8B%E7%BB%8D"><span class="toc-number">1.3.</span> <span class="toc-text">Docker命令介绍</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%95%9C%E5%83%8F%E7%AE%A1%E7%90%86%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="toc-number">1.3.1.</span> <span class="toc-text">镜像管理类命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E7%AE%A1%E7%90%86%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="toc-number">1.3.2.</span> <span class="toc-text">容器管理类命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E6%97%A5%E5%BF%97%E5%92%8C%E6%89%A7%E8%A1%8C%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="toc-number">1.3.3.</span> <span class="toc-text">容器日志和执行类命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%95%9C%E5%83%8F%E6%9E%84%E5%BB%BA%E5%92%8C%E7%AE%A1%E7%90%86%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="toc-number">1.3.4.</span> <span class="toc-text">镜像构建和管理类命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BD%91%E7%BB%9C%E5%92%8C%E5%AD%98%E5%82%A8%E7%AE%A1%E7%90%86%E7%B1%BB%E5%91%BD%E4%BB%A4"><span class="toc-number">1.3.5.</span> <span class="toc-text">网络和存储管理类命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Docker-Compose-%E7%9B%B8%E5%85%B3%E5%91%BD%E4%BB%A4"><span class="toc-number">1.3.6.</span> <span class="toc-text">Docker Compose 相关命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B3%E4%BA%8EDocker%E7%9A%84%E5%85%B6%E5%AE%83%E5%91%BD%E4%BB%A4%EF%BC%8C%E4%BB%A5%E5%90%8E%E7%94%A8%E5%88%B0%E4%BA%86%E5%86%8D%E5%81%9A%E8%A1%A5%E5%85%85%E2%80%A6%E2%80%A6"><span class="toc-number">1.3.7.</span> <span class="toc-text">关于Docker的其它命令，以后用到了再做补充……</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/netty-ai.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="netty的基本使用，基本原理分析，相关问题解(更新中...)"/></a><div class="content"><a class="title" href="/2023/11/21/netty%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8%EF%BC%8C%E5%9F%BA%E6%9C%AC%E5%8E%9F%E7%90%86%E5%88%86%E6%9E%90%EF%BC%8C%E7%9B%B8%E5%85%B3%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3-%E6%9B%B4%E6%96%B0%E4%B8%AD/" title="netty的基本使用，基本原理分析，相关问题解(更新中...)">netty的基本使用，基本原理分析，相关问题解(更新中...)</a><time datetime="2023-11-21T09:27:51.000Z" title="发表于 2023-11-21 17:27:51">2023-11-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/10/%E5%9C%A8conda%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%BF%90%E8%A1%8Cstable-diffusion-webui-AI%E7%BB%98%E5%9B%BE/" title="在conda环境下运行stable-diffusion-webui AI绘图"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在conda环境下运行stable-diffusion-webui AI绘图"/></a><div class="content"><a class="title" href="/2023/11/10/%E5%9C%A8conda%E7%8E%AF%E5%A2%83%E4%B8%8B%E8%BF%90%E8%A1%8Cstable-diffusion-webui-AI%E7%BB%98%E5%9B%BE/" title="在conda环境下运行stable-diffusion-webui AI绘图">在conda环境下运行stable-diffusion-webui AI绘图</a><time datetime="2023-11-10T07:30:51.000Z" title="发表于 2023-11-10 15:30:51">2023-11-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-11-10/ai.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)"/></a><div class="content"><a class="title" href="/2023/11/10/%E5%9C%A8Ubuntu20%E4%B8%8A%E5%AE%89%E8%A3%85CUDA-cuDNN-Miniconda%E7%8E%AF%E5%A2%83(%E5%85%B6%E5%AE%83%E7%B3%BB%E7%BB%9F%E5%90%8C%E7%90%86)/" title="在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)">在Ubuntu20上安装CUDA+cuDNN+Miniconda环境(其它系统同理)</a><time datetime="2023-11-10T07:27:51.000Z" title="发表于 2023-11-10 15:27:51">2023-11-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Docker Compose学习"/></a><div class="content"><a class="title" href="/2023/8/27/Docker-Compose%E5%AD%A6%E4%B9%A0/" title="Docker Compose学习">Docker Compose学习</a><time datetime="2023-08-27T15:34:50.000Z" title="发表于 2023-08-27 23:34:50">2023-08-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习"><img src="https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Dockerfile学习"/></a><div class="content"><a class="title" href="/2023/8/27/Dockerfile%E5%AD%A6%E4%B9%A0/" title="Dockerfile学习">Dockerfile学习</a><time datetime="2023-08-27T15:34:37.000Z" title="发表于 2023-08-27 23:34:37">2023-08-27</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://blog-1306275892.cos.ap-shanghai.myqcloud.com/hexo/blogs/2023-6-26/docker.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2024 By Fei</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text">欢迎进入<a href="tengfei2233.gitee.io/">飞の博客</a>!</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/utils.min.js"></script><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/main.min.js"></script><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/tw_cn.min.js"></script><script src="https://cdn.staticfile.org/fancyapps-ui/4.0.31/fancybox.umd.min.js"></script><script src="https://cdn.staticfile.org/instant.page/5.1.1/instantpage.min.js" type="module"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.staticfile.org/pangu/4.0.7/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: '0kbeJfFlvhvkYfqMqwwVCx1a-gzGzoHsz',
      appKey: 'rziWUw1MTHMW7d9eeCQzu9HV',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.staticfile.org/valine/1.5.1/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.staticfile.org/butterfly-extsrc/1.1.3/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="https://cdn.staticfile.org/hexo-theme-butterfly/4.7.0/js/search/local-search.min.js"></script></div></body></html>